package com.pan.admin.module.loanConfig.controller;

import com.pan.admin.common.annotation.Log;
import com.pan.admin.common.core.controller.BaseController;
import com.pan.admin.common.core.domain.AjaxResult;
import com.pan.admin.common.core.page.TableDataInfo;
import com.pan.admin.common.enums.BusinessType;
import com.pan.admin.common.utils.poi.ExcelUtil;
import com.pan.admin.module.loanConfig.entity.LoanProtocol;
import com.pan.admin.module.loanConfig.service.LoanProtocolService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;


/**
 * 协议配置(注册协议、隐私协议、单协议）Controller
 *
 * @author ts
 * @date 2023-09-27
 */
@RestController
@RequestMapping("/protocol/loanProtocol")
public class LoanProtocolController extends BaseController {
    @Autowired
    private LoanProtocolService loanProtocolService;

    /**
     * 查询协议配置(注册协议、隐私协议、单协议）列表
     */
    @PreAuthorize("@ss.hasPermi('protocol:loanProtocol:list')")
    @GetMapping("/list")
    public TableDataInfo list(LoanProtocol loanProtocol) {
        startPage();
        List<LoanProtocol> list = loanProtocolService.list(loanProtocol);
        return getDataTable(list);
    }

    /**
     * 导出协议配置(注册协议、隐私协议、单协议）列表
     */
    @PreAuthorize("@ss.hasPermi('protocol:loanProtocol:export')")
    @Log(title = "协议配置(注册-隐私-单协议)", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LoanProtocol loanProtocol) {
        List<LoanProtocol> list = loanProtocolService.list(loanProtocol);
        ExcelUtil<LoanProtocol> util = new ExcelUtil<LoanProtocol>(LoanProtocol.class);
        util.exportExcel(response, list, "协议配置(注册协议、隐私协议、单协议）数据");
    }

    /**
     * 获取协议配置(注册协议、隐私协议、单协议）详细信息
     */
    @PreAuthorize("@ss.hasPermi('protocol:loanProtocol:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(loanProtocolService.getById(id));
    }

    /**
     * 新增协议配置(注册协议、隐私协议、单协议）
     */
    @PreAuthorize("@ss.hasPermi('protocol:loanProtocol:add')")
    @Log(title = "协议配置(注册-隐私-单协议)", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LoanProtocol loanProtocol) {
        return toAjax(loanProtocolService.insertLoanProtocol(loanProtocol));
    }

    /**
     * 修改协议配置(注册协议、隐私协议、单协议）
     */
    @PreAuthorize("@ss.hasPermi('protocol:loanProtocol:edit')")
    @Log(title = "协议配置(注册-隐私-单协议)", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LoanProtocol loanProtocol) {
        return toAjax(loanProtocolService.updateLoanProtocol(loanProtocol));
    }

    /**
     * 删除协议配置(注册协议、隐私协议、单协议）
     */
    @PreAuthorize("@ss.hasPermi('protocol:loanProtocol:remove')")
    @Log(title = "协议配置(注册-隐私-单协议)", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(loanProtocolService.batchDeleteById(ids));
    }
}
